package com.killuasy.tools.servlet.magazine;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Properties;
//import java.util.regex.Matcher;
import java.util.regex.Pattern;

import com.killuasy.utils.io.DownloadUtil;
import com.killuasy.utils.io.OutPutFile;
import com.killuasy.utils.SysInit;
import java.net.*;
import java.io.*;

import com.sonalb.net.http.cookie.Client;
import com.sonalb.net.http.cookie.CookieJar;

public class WwwVvshuComMain {

	/**
	 * @param args
	 */
	public static void main(String[] args) {

		// get url
		Properties props = new Properties();
		try {
			props.load(new InputStreamReader(new FileInputStream(
					"wwwVvshuCom.properties"), SysInit.propEncoding));
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}

		String rootURL = (String) props.get("rootURL");
		String subURL = (String) props.get("subURL");
		String clickURL = (String) props.get("clickURL");
		String encoding = (String) props.get("encoding");
		String outPutFileName = (String) props.get("outPutFileName");
		int pageNums = Integer.parseInt((String) props.get("pageNums"));

		System.out.println("Processing URL Start Download.");

		String urlStr = null;
		URL url;
		System.out.println("page1");
		urlStr = clickURL;
		try {
			url = new URL(urlStr);
			// WebUtil.readPageSource(url, encoding);

			// HttpURLConnection huc = (HttpURLConnection) url.openConnection();
			// huc.connect();
			//
			// Client client = new Client();
			// CookieJar cj = client.getCookies(huc);
			// huc.disconnect();
			Runtime r = Runtime.getRuntime();
			r.exec("D:\\Tool\\Firefox4\\firefox\\.exe "
					+ urlStr);
			
			
//			 DownloadUtil.DownloadFile(rootURL+subURL+"001.jpg",
//			 "001.jpg");

		} catch (MalformedURLException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}

		// for (int i = 2; i <= pageNums; i++) {
		// System.out.println("page"+i);
		// url = clickURL + "?" + i;
		// WebUtil.readPageSource(url, encoding);
		// }

		System.out.println("Processing URL End Download.");
		System.out.println("=================================");
	}

}
